package lol.clann.minecraft.springboot.plugin.core.model;

import lol.clann.minecraft.springboot.api.model.core.Plugin;
import relocate.ninja.leaping.configurate.commented.CommentedConfigurationNode;
import org.springframework.core.env.PropertySource;

/**
 * 将插件包装成一个PropertySource,供SpringEnvironment使用
 *
 * @author pyz
 * @date 2019/6/22 5:27 PM
 */
public class PluginConfigPropertySouce extends PropertySource<Plugin> {

    public PluginConfigPropertySouce(Plugin plugin) {
        super(plugin.getId(), plugin);
    }

    @Override
    public Object getProperty(String name) {
        CommentedConfigurationNode node = getSource().getConfigurationNode().getNode(name.split("\\."));
        if (node.isVirtual()) {
            return null;
        } else {
            return node.getString();
        }
    }
}
